import store from "../store/store.js";
import api from "./api.js";

export function getGameStateUnilateral() {
    return new Promise((resolve, reject) => {
        api.get('/game/getGameStateUnilateral').then(res => {
            store.commit('setGameStateUnilateral', res.data)
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    });
}
export function getGameStateSymmetry() {
    return new Promise((resolve, reject) => {
        api.get('/game/getGameStateSymmetry').then(res => {
            store.commit('setGameStateSymmetry', res.data)
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    });
}
export function getGamePetsPick() {
    return new Promise((resolve, reject) => {
        let hidden_open = store.state.game.hidden_open
        api.get('/game/getGamePetsPick', {
            params: {
                hidden_open: hidden_open
            }
        }).then(res => {
            store.commit('setGamePetsPick', res.data)
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    });
}
export function getEnableItem(pageNo, pageSize) {
    return new Promise((resolve, reject) => {
        api.get('/game/getEnableItem',
            {
                params: {
                    page_no: pageNo,
                    page_size: pageSize
                }
            }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    });
}
export function banHidePets() {
    return new Promise((resolve, reject) => {
        api.get('/game/banHidePets').then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
/*
payload: {
    value: number // 选择值
    hidden: boolean // 是否暗手
}
 */
export function playerAction(payload) {
    return new Promise((resolve, reject) => {
        api.post('/banpick/playerAction', payload).then(res => {
            store.commit('setHidden', false)
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    });
}
export function rollType() {
    return new Promise((resolve, reject) => {
        api.post('/banpick/rollType').then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    });
}